package com.wsh.entity.sys;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wsh.utils.SecurityUtils;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @Author 王思涵
 * @Date 2019/7/20
 * @Version 1.0
 * @Desciption
 **/
@Data
@TableName("sys_user")
public class UserEntity implements UserDetails {
    private static final long serialVersionUID = 1L;

    /**
     * 用户id
     */
    @TableId(type = IdType.UUID)
    private String userId;

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 用户邮箱
     */
    private String email;

    /**
     * 真实姓名
     */
    private String realName;

    /**
     * 用户状态 0：禁用 1：正常
     */
    private Integer status;

    /**
     * 用户角色
     */
    private String roleId;

    /**
     * 用户部门
     */
    private String depId;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 更新时间
     */
    @TableField(update = "NOW()", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    /**
     * 头像
     */
    @TableField(exist = false)
    private String[] photo;

    @TableField(exist = false)
    private String avatarImg;

    /**
     * 头像
     */
    @TableField(exist = false)
    private String avatarUrl;

    /**
     * 权限
     */
    @TableField(exist = false)
    private List<MenuEntity> menuEntityList;

    /**
     * 角色名称
     */
    @TableField(exist = false)
    private String roleName;

    /**
     * 部门名称
     */
    @TableField(exist = false)
    private String depName;

    /**
     * 路由
     */
    @TableField(exist = false)
    private String[] menus;

    @TableField(exist = false)
    private String code;

    @TableField(exist = false)
    private String Uuid;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return SecurityUtils.getUserDetails().getAuthorities();
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
